package com.gl.multipleyes.api

import com.gl.multipleyes.User
import grails.converters.JSON

class UserController {
	static namespace = "api"

	def show() {
		def user = null,
			userID = params.id

		if (userID == null || !userID.toString().isNumber()) {
			render "Error"
		} else {
			user = User.findByExternalId(userID)
		}
		render user?: user as JSON    // Provisorio
	}
	
	def index() {
		println "entre"
		render User.list() as JSON

			}

	def save(User user) {
		def userParams = params
		def flag = true

		if (userParams == null) {
			render "Error"
		} else {
			userParams.each { key, value ->
				if (value == null) {
					flag = false
				}
			}
		}
		if (flag) {
			user.save()
			render "OK -> ${user.name}"
		} else {
			render "Error"
		}
	}
}
